package com.uenpay.im.invokeitems.chat;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;


/**
 * 申请加入群聊
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class ApplyJoinGroupInvokeItem extends BaseHttpInvokeItem {
	public class ApplyJoinGroupInvokeItemResult extends HttpInvokeResult {
		public int status;
		public String msg;
	}

	public ApplyJoinGroupInvokeItemResult getOutput() {
		return (ApplyJoinGroupInvokeItemResult) GetResultObject();
	}

	public ApplyJoinGroupInvokeItem(String chat_id) {
		String url = APIConfiguration.getBaseUrl() + "Chat/Chat/applyJoin?"
				+ APIConfiguration.getCustIdAndToken();
		HashMap<String, String> mRequestParams = new HashMap<String, String>();
		mRequestParams.put("chatid", chat_id);
		SetRequestParams(mRequestParams);
		RequestHttpInvokeItem(true);
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		ApplyJoinGroupInvokeItemResult result = new ApplyJoinGroupInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}

}
